import * as echarts from "echarts";
const echartInstance = {}; //所有图的实例对象
export const overViewMap = {
	'放款总量': { dto: 'fkzlDto', amount: 'amount', biNum: 'biNum' },
	'备案总量': { dto: 'bazlDto', amount: 'amount', biNum: 'biNum' },
	'在保余额': { dto: 'zbyeDto', amount: 'amount', biNum: 'biNum' },
	'代偿总量': { dto: 'dczlDto', amount: 'amount', biNum: 'biNum' },
	'代偿审查总量': { dto: 'dcscDto', amount: 'amount', biNum: 'biNum' },
	'代偿收回总量': { dto: 'dcshDto', amount: 'amount', biNum: 'biNum' },
	'保费收取总量': { dto: 'bfsqDto', amount: 'amount', biNum: 'biNum' },
	'收回补偿总量': { dto: 'shbcDto', amount: 'amount', biNum: 'biNum' }
};
//生成企业登记所在地数据
export function createQydjszdData(data){
	return data.map(item => {
		return {
			value:item.ct,
			name:item.djszd
		}
	});
}
//生成担保银行占比数据
export function createDbyhData(data){
	return data.map(item => {
		return {
			value:item.ct,
			name:item.sx
		}
	});
}
//生成担保产品排名数据
export function createDbcpData(data){
	const Xdata = [];
	const Ydata = [];
	data.forEach((item,index) => {
		Xdata.push(item.dbcp)
		if(index < 3){
			Ydata.push({
				value:item.num,
				itemStyle:{
					color: '#4666F2'
				}
			})
		}else{
			Ydata.push(item.num)
		}
	});
	return {
		Xdata,
		Ydata
	}
}
//生成企业行业排名数据
export function createQyhyData(data){
	const Xdata = [];
	const Ydata = [];
	data.forEach((item,index) => {
		Xdata.push(item.hy)
		if(index < 3){
			Ydata.push({
				value:item.num,
				itemStyle:{
					color: '#4666F2'
				}
			})
		}else{
			Ydata.push(item.num)
		}
	});
	return {
		Xdata,
		Ydata
	}
}
//生成业务信息数据
export function createYwxxData(data){
	const xAxisData = [] // ['6月','7月','8月','9月','10月','11月','12月'];
	const fkData = [];
	const jbData = [];
	const dcData = [];
	data.forEach((item) => {
		xAxisData.push(item.rq)
		fkData.push(item.fkAmount || 0)
		jbData.push(item.jbAmount || 0)
		dcData.push(item.dcAmount || 0)
	});
	const seriesData = [{
			name: '放款',
			type: 'line',
			symbolSize: 10,
			data: fkData //[120, 1320, 101, 134, 90, 230, 210]
		}, {
			name: '放款笔数',
			type: 'line',
			symbolSize: 10,
			data: [1200, 132, 1010, 1340, 900, 2300, 2100],
			yAxisIndex: 1,
		}, {
			name: '解保',
			type: 'line',
			symbolSize: 10,
			data: jbData //[220, 182, 191, 234, 290, 330, 310]
		}, {
			name: '解保笔数',
			type: 'line',
			symbolSize: 10,
			data: [150, 232, 201, 154, 190, 330, 410],
			yAxisIndex: 1,
		}, {
			name: '代偿',
			type: 'line',
			symbolSize: 10,
			data: dcData //[320, 332, 301, 334, 390, 330, 320]
		},
		{
			name: '代偿笔数',
			type: 'line',
			symbolSize: 10,
			data: [820, 932, 901, 934, 1290, 1330, 1320],
			yAxisIndex: 1,
		}
	];
	const series = seriesData.map(item => {
		return {
			...item,
			lineStyle: {
				type: item.yAxisIndex ? 'dashed' : 'solid'
			}
		}
	}).filter(item => item.yAxisIndex != 1)
	return {
		xAxisData, series
	}
}
//生成费用收取数据
export function createFysqData(data){
	const xAxisData = [] // ['6月','7月','8月','9月','10月','11月','12月'];
	const bcData = []
	const bfData = []
	const zcData = []
	data.forEach((item) => {
		xAxisData.push(item.rq)
		bcData.push(item.bcAmount)
		bfData.push(item.bfAmount)
		zcData.push(item.zcAmount)
	});
	const seriesData = [{
			name: '补偿金额',
			type: 'line', 
			symbolSize: 10,
			data: bcData //[120, 1320, 101, 134, 90, 230, 210]
		}, {
			name: '放款笔数',
			type: 'line',
			symbolSize: 10,
			data: [1200, 132, 1010, 1340, 900, 2300, 2100],
			yAxisIndex: 1,
		}, {
			name: '保费金额',
			type: 'line',
			symbolSize: 10,
			data: bfData //[220, 182, 191, 234, 290, 330, 310]
		}, {
			name: '解保笔数',
			type: 'line',
			symbolSize: 10,
			data: [150, 232, 201, 154, 190, 330, 410],
			yAxisIndex: 1,
		}, {
			name: '追偿金额',
			type: 'line',
			symbolSize: 10,
			data: zcData //[320, 332, 301, 334, 390, 330, 320]
		},
		{
			name: '代偿笔数',
			type: 'line',
			symbolSize: 10,
			data: [820, 932, 901, 934, 1290, 1330, 1320],
			yAxisIndex: 1,
		}
	];
	const series = seriesData.map(item => {
		return {
			...item,
			lineStyle: {
				type: item.yAxisIndex ? 'dashed' : 'solid'
			}
		}
	}).filter(item => item.yAxisIndex != 1);
	return {
		xAxisData, series
	}
}
//饼图
export const createPieOptions = (echartData) => {
	let instance, option;
	const { documentID } = echartData;
	if (echartInstance.documentID) {
		instance = echartInstance.documentID;
	} else {
		instance = echarts.init(document.getElementById(documentID));
	}
	option = {
		legend: {
		    top: 'bottom',
			icon:'circle'
		},
		tooltip: {
			//   trigger: "item",
			formatter: '{b} : {c} ({d}%)'
		},
		label: {
			show: true, // 显示标签
			formatter: '{d}%' // 自定义标签内容，{b} 是 name，{d} 是占比
		},
		
		series: [{
			name: "",
			type: "pie",
			radius:[12, 110],
			roseType: 'area',
			labelLine: {
				show: true,
				length:2,
				length2: 5 // 第二段引导线长度固定
			}
		}],
		
	};
	instance.setOption(option);
	window.addEventListener("resize", () => {
		instance.resize();
	});
	return instance;
};
//柱状图
export const createBarOptions = (echartData) => {
	let instance, option;
	const { documentID } = echartData;
	if (echartInstance.documentID) {
		instance = echartInstance.documentID;
	} else {
		instance = echarts.init(document.getElementById(documentID));
	}
	option = {
		tooltip: {
			trigger: "axis",
			axisPointer: {
				type: "shadow",
			},
		},
		grid: {
			left: "3%",
			right: "4%",
			bottom: "3%",
			containLabel: true,
		},
		xAxis: [{
			type: "category",
			axisTick: {
				alignWithLabel: true,
			},
			axisLabel: {
				rotate: 45,
			},
		}, ],
		yAxis: [{
			type: "value",
		}, ],
		series: [{
			name: "数量",
			type: "bar",
			barWidth: "60%",
		}],
	};
	instance.setOption(option);
	window.addEventListener("resize", () => {
		instance.resize();
	});
	return instance;
};

//折线图
export const createLineOptions = (echartData) => {
	let instance, option;
	const { documentID } = echartData;
	if (echartInstance.documentID) {
		instance = echartInstance.documentID;
	} else {
		instance = echarts.init(document.getElementById(documentID));
	}
	option = {
		color:['#5698D2','#F97764','#4666F2'],
		tooltip: {
			trigger: 'axis',
			axisPointer: {
				type: 'cross'
			}
		},
		legend: {
			top: "bottom",
		},
		grid: {
			left: '1%',
			right: '4%',
			bottom: '6%',
			top: '20%',
			containLabel: true
		},

		xAxis: {
			type: 'category',
			boundaryGap: false
		},
		yAxis: [{
				name: '金额',
				type: 'value',
				axisLine: {
					show: true
				}
			},
			//   {
			//     name: '笔数',
			//     type: 'value'
			//   }
		],
	};
	instance.setOption(option);
	window.addEventListener("resize", () => {
		instance.resize();
	});
	return instance;
}